package cn.codeforfun.controller

import cn.codeforfun.entity.User
import cn.codeforfun.service.UserService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@RestController
open class UserController {
    @Autowired
    private var userService: UserService? = null

    @RequestMapping("/{id}", method = arrayOf(RequestMethod.GET))
    fun get(@PathVariable id: String): User = userService?.findById(id) as User

    @RequestMapping(method = arrayOf(RequestMethod.POST))
    fun save(@RequestBody user: User) = userService?.save(user)

    @RequestMapping(method = arrayOf(RequestMethod.GET))
    fun list(): List<User> = userService?.findAll() as List<User>

}


